package com.logic.modular.act.cultivate;

import cn.hutool.core.bean.BeanUtil;
import com.comment.util.message.ResponseResult;
import com.logic.comment.util.JwtUtils;
import com.logic.modular.act.cultivate.vo.CultivateVo;
import com.comment.pojo.domain.bag.BagItem;
import com.logic.modular.game.player.bag.dto.UsePropDto;
import com.logic.modular.game.player.bag.service.BagItemServiceImpl;
import com.logic.modular.game.player.bag.service.PlayerPropType2ServiceImpl;
import com.logic.modular.game.player.bag.service.PlayerPropType3ServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 背包物品(PlayerBag)表服务控制层
 *
 * @author cxy
 * @since 2024-07-26 17:49:04
 */
@Api(tags = "玩家物品")
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/playerBagAct")
public class PlayerBagAction {
    @Resource
    private BagItemServiceImpl bagItemService;
    @Resource
    private PlayerPropType2ServiceImpl playerPropType2Service;
    @Resource
    private PlayerPropType3ServiceImpl playerPropType3Service;

    @ApiOperation("玩家背包信息")
    @PostMapping("/list")
    public ResponseResult<List<BagItem>> list(@RequestHeader String token) {
        return ResponseResult.success(bagItemService.list(
                JwtUtils.getPlayerId(token)));
    }

    @ApiOperation("使用道具")
    @PostMapping("/useProp")
    public ResponseResult<?> useProp(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerBagVo.useProp vo
    ) {
        UsePropDto bean = BeanUtil.toBean(vo, UsePropDto.class);
        bean.setUid(JwtUtils.getPlayerId(token));
        playerPropType2Service.useProp(bean);
        return ResponseResult.success();
    }

    @ApiOperation("使用礼包")
    @PostMapping("/useGiftPack")
    public ResponseResult<?> useGiftPack(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerBagVo.useGiftPack vo
    ) {
        playerPropType3Service.useGiftPack(
                JwtUtils.getPlayerId(token),
                vo.getCorePropId(),  vo.getSelectionOptions());
        return ResponseResult.success();
    }

    @ApiOperation("回收道具")
    @PostMapping("/recycleProp")
    public ResponseResult<?> recycleProp(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerBagVo.recycleProp vo
    ) {
        return ResponseResult.success(bagItemService.recycleProp(JwtUtils.getPlayerId(token),vo.getPlayerBagItemId(),vo.getNum()));
    }
}
